<?php 

/* security check
if (count($_POST) > 0) {
	foreach ($_POST as $key => $value) {
		$message .= "$key : $value\n\n";
	}
	mail("lforget@statnet.ca", "Post Vars", "$message");
}
*/

// IMAGE VERIFICATION MOD BY STATNET PRODUCTIONS. EMAIL lforget@statnet.ca IF YOU HAVE QUESTIONS

session_start();
header("Cache-control: private");

$submit =      $_POST['submit'];   
$dest_city =   $_POST['dest_city'];
$type = 			 $_POST['type'];     
$name = 			 $_POST['name'];          
$frequency =   $_POST['frequency'];
$id         =  $_POST['id'];       
$orig_city  =  $_POST['orig_city'];
$margin     =  $_POST['margin'];   
$email      =  $_POST['email'];    
$phone      =  $_POST['phone'];    
$license    =  $_POST['license'];  
$comments   =  $_POST['comments']; 
$costs      =  $_POST['costs'];    
$smoker     =  $_POST['smoker'];   
$interests  =  $_POST['interests'];
               
$start_time =  $_POST['start_time'];
$days_show  =  $_POST['days_show'];
$end_time   =  $_POST['end_time'];
$date       =  $_POST['date'];

$verify_form = $_POST['verify_form'];


if (isset($submit) && !$delete) {
 $verify = $_SESSION['verify'];

 if ($verify_form != $verify) {
  header('Location: error.html');
  exit();
 }
}

elseif (isset($submit) && isset($delete)) {
// Do nothing
}

else {
 $random = mt_rand(1,3);

 $verify_image = "verify0" . $random . ".jpg";

 if ($verify_image == "verify01.jpg") {
  $verify = "7845";
 }
 elseif ($verify_image == "verify02.jpg") {
  $verify = "4582";
 }
 else {
  $verify = "8862";
 }

 $_SESSION['verify'] = $verify;
}

?>

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=ISO-8859-1">
<title>Rideshare</title>
<link rel="stylesheet" type="text/css" href="../external.css">
</head>

<?php

include("../header.php") ;
include('../dbconnect.php'); 

// ADD OR EDIT A RECORD IN THE DATABASE

if ($submit && $orig_city && $dest_city && $type && $name) {
//echo "$days_show";

	$ip_addy = $_SERVER['REMOTE_ADDR'];

	$sql = "REPLACE INTO local (id, type, orig_city, start_time, dest_city, days_show, end_time, date, margin, email, phone, name, license, comments, frequency, costs, smoker, interests, date_time, ip_addy ) VALUES ( '$id', '$type', '$orig_city', '$start_time', '$dest_city', '$days_show', '$end_time', '$date', '$margin', '$email', '$phone', '$name', '$license', '$comments', '$frequency', '$costs', '$smoker', '$interests', NOW(), '$ip_addy' )"; 
	//echo $sql;
	$result = mysql_query($sql) or die("could not add the record to the database, an error occurred.<br>");
	echo "<center><p><b>Your ride was added successfully.</b></p></center>";

} elseif ($submit && $delete) {
    $sql = "DELETE FROM local WHERE id=$id";	 
    $result = mysql_query($sql);
    echo "<center><h2>Record deleted</h2></center>";

} elseif ($submit) {
    echo "<center><br><h2>Error. Please make sure all the required fields in the form are complete: <br> ride type, origin city, destination city, and name. <br><br>Click on the back button.</h2> </center>";
    
} else {

// GENERATE HTML TO EDIT OR ADD A RECORD 

$phone = "";

if ($id) {
    $sql = "SELECT * FROM local WHERE id=$id";
    $result = mysql_query($sql);
    $myrow = mysql_fetch_array($result);
    
	$id = $myrow["id"];
	$type = $myrow["type"];
	$orig_city = $myrow["orig_city"];
	$start_time = $myrow["start_time"];
	$dest_city = $myrow["dest_city"];
	$days_show = $myrow["days_show"];
	$end_time = $myrow["end_time"];
	$date = $myrow["date"];
	$margin = $myrow["margin"];
	$email = $myrow["email"];
	$phone = $myrow["phone"];
	$name = $myrow["name"];
	$license = $myrow["license"];
	$comments = $myrow["comments"];
	$frequency = $myrow["frequency"];
	$costs = $myrow["costs"];
	$smoker = $myrow["smoker"];
	$interests = $myrow["interests"];
	
	list ($year, $month, $day) = explode ("-", $date);
}
	
   if ($id) {  echo "<h1 align=center>Edit an Existing Trip</h1>"; 
   } else { echo "<h1 align=center>Add a New Frequent/Commuter Trip</h1>"; }
   
?>

<?php
if ($id) {
echo "<center><form method='post' name='delete' action='$PHP_SELF'>";
echo "<input type='hidden' name='id' value='$id'>";
echo "<input type='hidden' name='delete' value='1'>";
echo "<input type='submit' value='Delete this Ride' name='submit'>";
echo "</form></center>";
}
?>

<div style='text-align: center'>
<br/>
<script type="text/javascript"><!--
google_ad_client = "pub-9558928185904351";
/* 468x60, created 3/26/09 rideshare */
google_ad_slot = "5990395066";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<br/>
</div>

<p><form method="post" name="addride" action="<?php echo $PHP_SELF ?>">
	<input type="hidden" name="id" value="<?php echo $id ?>">
	<input type="hidden" name="date" value="<?php echo date("Y-m-d") ?>">
		
    <table align="center" border="0" cellpadding="1" cellspacing="0" width="700" bgcolor="#666633">
      <tr>	
      	<td> 
      	   
      <table align="center" border="0" cellpadding="6" cellspacing="1" width="700" bgcolor="#CCCC99">
      <tr>	
        <th width="35%"><b>Fields</b></th>
        <th width="65%"><b>Ride Details</b></th>
      </tr>		
      <tr>	
        <td><b>Ride Type</b></td>
        <td>
          <input type="radio" value="offering" name="type" <?php if ( ereg("offering",$type) ) {echo "checked";} ?> >
          I have a car and am looking for passengers (Driver)<br>
          <input type="radio" value="looking" name="type" <?php if ( ereg("looking",$type) ) {echo "checked";} ?> >
          I want a ride with someone who has a car (Passenger) <br> </td>
      </tr>			
      <tr>	
        <td><b>Starting Point:</b><br>
        include area if important</td>
        <td>City<input type="text" name="orig_city" value="<?php echo $orig_city ?>" size="40"></td>
      </tr>		
      <tr>	
        <td><b>Destination:</b><br>
        include area if important</td>
        <td>City<input type="text" name="dest_city" value="<?php echo $dest_city ?>" size="40"></td>
      </tr>		
      <tr>	
     <!--   <td><b>Detours:</b><br>
        Drivers: Are you willing to detour to pick up a rider?</td>
        <td><input type="text" name="detour" value="<?php echo $detour ?>" size="20"></td>
      </tr>	-->	
      <tr>	
        <td><b>Trip Schedule:</b><br>
        Please give the details of your schedule here (daily, weekly, or specific days of the week)</td>
        <td><textarea name="frequency" cols="45" rows="4" wrap="virtual"><?php echo $frequency ?></textarea></td>
      </tr>			
      <tr>	
        <td><b>Start Time:</b></td>
        <td><input type="text" name="start_time" value="<?php echo $start_time ?>" size="20"></td>
      </tr>			
      <tr>	
        <td><b>Return Time:</b></td>
        <td><input type="text" name="end_time" value="<?php echo $end_time ?>" size="20"></td>
      </tr>	
      <tr>	
        <td><b>Other Trip Info</b><br>
        Do you want to drive or ride all the time or alternate, is your schedule fixed or flexible, will you detour to pick up a rider?, other comments</td>
        <td><textarea name="comments" cols="45" rows="7" wrap="virtual"><?php echo $comments ?></textarea></td>
      </tr>
      <tr>	
        <td><b>Months to display:</b><br>
        How long do you want your trip to stay on this website?</td>
        <td><select name="days_show">
<option value="30" <? if ($days_show==30){echo "selected";}?> >1 months</option>
<option value="60" <? if ($days_show==60){echo "selected";}?> >2 months</option>
<option value="90" <? if ($days_show==90 || $days_show==""){echo "selected";}?> >3 months</option>
<option value="180" <? if ($days_show==180){echo "selected";}?> >6 months</option>
<option value="365" <? if ($days_show==365){echo "selected";}?> >12 months</option>
</select></td>
      </tr>		
      <tr>	
        <td><b>Sharing Costs:</b><br>
        Whether you'll be charging passengers or willing to share car costs.</td>
        <td><input type="text" name="costs" value="<?php echo $costs ?>" size="50"></td>
      </tr>		
      <tr>	
        <td><b>Your Name:</b></td>
        <td><input type="text" name="name" value="<?php echo $name ?>" size="50"></td>
      </tr>		
      <tr>	
        <td><b>Phone:</b></td>
        <td><input type="text" name="phone" value="<?php echo $phone ?>" size="20"></td>
      </tr>		
      <tr>	
        <td><b>Email:</b><br>
        Your email address will remain private, we will not give it to anyone.</td>
        <td><input type="text" name="email" value="<?php echo $email ?>" size="50"></td>
      </tr>		
      <tr>	
        <td><b>Driving Ability:</b><br>
        Do you have a license? Can you drive standard?</td>
        <td><input type="text" name="license" value="<?php echo $license ?>" size="50"></td>
      </tr>		
      <tr>	
        <td><b>Do you smoke:</b></td>
        <td><input type="text" name="smoker" value="<?php echo $smoker ?>" size="50"></td>
      </tr>		
      <tr>	
        <td><b>Interests & Hobbies:</b></td>
        <td><input type="text" name="interests" value="<?php echo $interests ?>" size="50"></td>
      </tr>
      <tr>
        <td><b>Image Authentication:</b></td>
        <td><img src="images/<?php echo $verify_image; ?>">&nbsp;&nbsp;<input type="text" name="verify_form" size="4"><br>Please enter the number you see above for verification</td>
      </tr>	
      <tr>	
        <td align="center" colspan="2"><input type="submit" value="Submit Ride" name="submit"></td>
      </tr>
    </table>
    </td>
      </tr>
    </table>
</form>

</p>

<div style='text-align: center'>
<br/>
<script type="text/javascript"><!--
google_ad_client = "pub-9558928185904351";
/* 468x60, created 3/26/09 rideshare */
google_ad_slot = "5990395066";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<br/>
</div>
		
<?php
} 
 include("../footer.php"); 
?>
</html>
